﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZYCommon;
using TextEditor.TextDocument.Document;

namespace TextEditor.TextDocument.Control
{
    public partial class frmSetPageHead : Form
    {
        ZYTextDocument document = null;
        public frmSetPageHead(ZYTextDocument myDocument)
        {
            InitializeComponent();
            document = myDocument;
        }

        private void dgvheader_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvheader.Rows.Count > 0 && e.ColumnIndex == 6 && e.RowIndex >= 0)
            {
                dgvheader.Rows.Remove(dgvheader.Rows[e.RowIndex]);
            }
        }

        Image image = null;
        private void button3_Click(object sender, EventArgs e)
        {
            if (image == null)
            {
                image = new Bitmap(document.Pages.StandardWidth, document.Pages.StandardHeight);
            }
            using (Graphics g = Graphics.FromImage(image))
            {
                using (Brush b = new SolidBrush(Color.White))
                {
                    using (Pen p = new Pen(Color.Black))
                    {
                        //GetTheThousandthsOfAnInch
                        g.FillRectangle(b, 0, 0, image.Width, image.Height);
                        for (int i = 0; i < dgvheader.Rows.Count - 1; i++)
                        {
                            DataGridViewRow row = dgvheader.Rows[i];
                            string value = row.Cells[0].Value.ToString();
                            switch (value)
                            {
                                case "图片":
                                    break;

                                case "线段":
                                    g.DrawLine(p, ConvertToInt(row.Cells[2].Value), ConvertToInt(row.Cells[3].Value), ConvertToInt(row.Cells[4].Value), ConvertToInt(row.Cells[5].Value));
                                    break;

                                case "数据字段":
                                    break;

                                case "文本": 
                                    //g.DrawLine(p, ConvertToInt(row.Cells[2].Value), ConvertToInt(row.Cells[3].Value));
                                    break;
                            }
                        }
                    }
                }


            }
            pictureBox1.Image = image;
        }
        public int ConvertToInt(object value)
        {
            int zhuanhuan = 0;
            int.TryParse(value.ToString(), out zhuanhuan);
            return ZYTextDocument.GetTheThousandthsOfAnInch(zhuanhuan);
        }
    }
}
